# Contributor: kpcyrd <git@rxv.cc>
# Maintainer: kpcyrd <git@rxv.cc>
pkgname=meek
pkgver=0.38.0
pkgrel=5
pkgdesc="Pluggable transport proxy written in Go"
url="https://trac.torproject.org/projects/tor/wiki/doc/meek"
arch="all !riscv64" # fails to build on riscv64
license="CC0-1.0"
depends="ca-certificates"
makedepends="go libcap-utils"
subpackages="
	$pkgname-doc
	$pkgname-server
	"
source="https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/meek/-/archive/v$pkgver/meek-v$pkgver.tar.bz2
	binary-location.patch
	"
builddir="$srcdir/meek-v$pkgver"
# no test suite available
options="!check chmod-clean setcap"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	for proj in meek-client meek-server; do
		go build \
			-ldflags "-extldflags '$LDFLAGS'" \
			-o $proj/$proj ./$proj/...
	done
}

package() {
	install -Dm755 meek-client/meek-client meek-server/meek-server \
		-t "$pkgdir"/usr/bin/

	setcap cap_net_bind_service=+ep "$pkgdir"/usr/bin/meek-server

	install -Dm644 doc/*.1 -t "$pkgdir/usr/share/man/man1"
	install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"

	install -Dm644 README "$pkgdir/usr/share/doc/$pkgname/README"
	install -Dm644 meek-server/README "$pkgdir/usr/share/doc/$pkgname/README.meek-server"

	install -Dm644 meek-client/torrc \
		"$pkgdir/usr/share/doc/$pkgname/torrc.meek-client"
	install -Dm644 meek-server/torrc \
		"$pkgdir/usr/share/doc/$pkgname/torrc.meek-server"
}

server() {
	pkgdesc="meek pluggable transport proxy server"
	depends=

	amove usr/bin/meek-server
}

sha512sums="
2ee2461b1e4174b555530dc4a3a85513ea0fdd741dc0708954a08794110343a09a8dff3d855c3c5788f212701f49ed67f9a442b9d064655f6c9760ea5e083b9f  meek-v0.38.0.tar.bz2
4399f76cd31c3be0e28b6ac82059c4fc66f5e720c65e2f51922041a5b08a5f9f1959871055727bf068f4b621629c943e9d97368d6af3db8a8e1c9cdf5edc043c  binary-location.patch
"
